package com.yin.myproject.netty;

import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.LineBasedFrameDecoder;
import io.netty.handler.codec.string.StringDecoder;

/**
 * @author Eason
 * @create 2017-12-24 17:36
 **/
public class ChildServerHandler extends ChannelInitializer<SocketChannel> {

    protected ChannelHandler channelAdapter;

    public ChildServerHandler(ChannelHandler channelAdapter) {
        this.channelAdapter = channelAdapter;
    }

    @Override
    protected void initChannel(SocketChannel socketChannel) throws Exception {
        socketChannel.pipeline().addLast(new LineBasedFrameDecoder(1024));
        socketChannel.pipeline().addLast(new StringDecoder());
        socketChannel.pipeline().addLast(channelAdapter);
    }
}
